<?php

class Config {
	protected $data;
	private static $instance = null;
	
	public function instance() {
		if (self::$instance === null) {
			$class = __CLASS__;
			self::$instance = new $class;
		}
		return self::$instance;
	}
	
	protected static function load($src) {
		if (File::exists(File::extension($src, 'php'))) {
			return require_once File::extension($src, 'php');
		}
	}
	
	public function load_from_app($src) {
		if (is_array($src)) {
			foreach ($src as $config) {
				$file = self::load_from_app($config);
			}
			return $file;
		}
		return self::load(CONFIG . $src);			
	}
	
	public static function load_from_theme($src) {
		if (is_array($src)) {
			foreach ($src as $config) {
				$file = self::load_from_theme($config);
			}
			return $file;
		}
		return self::load(THEME . self::instance()->data['theme'] . DS . 'configs' . DS . $src);	
	}
	
	public static function write($var, $value) {
		self::instance()->data[$var] = $value;
		return self::instance()->data;
	}
	
    public static function read($name) {
        return self::instance()->data[$name];
    }

	public function __get($name) {
        return self::read($name);
    }
}

?>